<?php
/**
 * Created by PhpStorm.
 * User: HHZ
 * Date: 2018/12/13
 * Time: 15:21
 */

namespace Biz\model\activity;

use Doraemon\pockets\datebase\BaseDbModel;
use Doraemon\tools\ImgUrl;

class NewComer extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_activity';

    const _DATABASE_ = 'shop_activity';

    const _TABLE_NAME = 'newcomer';

    public static function saveNewComer($list, $newComerId)
    {
        if(isset($newComerId) && $newComerId > 0) {
            $result = self::update($list, ['id' => $newComerId])->rowCount();
            if($result) {
                return $newComerId;
            }
        } else {
            $list['addtime'] = date('Y-m-d H:i:s');
            $result = self::insert($list)->rowCount();
            if($result) {
                return self::id();
            }
        }
        return false;
    }

    public static function getInfo()
    {
        $info = self::get('*');
        self::formatInfo($info);
        return $info;
    }

    private static function formatInfo(&$info)
    {
        if($info) {
            if($info['goods_icon_id']) {
                $info['goods_icon_url'] = ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $info['goods_icon_id'], ImgUrl::IMAGE_SIZE_ORI_NPHONE);
            }
            if($info['goods_banner_id']) {
                $info['goods_banner_url'] = ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $info['goods_banner_id'], ImgUrl::IMAGE_SIZE_ORI_NPHONE);
            }
        }
    }
}